package com.api.weavernorth.LogWeaTable.cmd;

import com.api.browser.bean.SearchConditionGroup;
import com.api.browser.bean.SearchConditionItem;
import com.api.browser.bean.SearchConditionOption;
import com.api.browser.util.ConditionFactory;
import com.api.browser.util.ConditionType;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.weavernorth.util.dateUtils;
import weaver.hrm.User;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: BruseeWang
 * @Date: 2021/12/08 16:23
 * @Description: 获取高级搜索条件
 */
public class WeatableConditonLogCmd extends AbstractCommonCommand<Map<String,Object>> {

    public WeatableConditonLogCmd(User user, Map<String,Object> params) {
        this.user = user;
        this.params = params;
    }

    @Override
    public BizLogContext getLogContext() {
        return null;
    }

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {

        Map<String, Object> apidatas = new HashMap<String, Object>();
        //角色判断参考代码
//        if(!HrmUserVarify.checkUserRight("LogView:View", user)){
//            apidatas.put("hasRight", false);
//            return apidatas;
//        }

        if (null == user){
            apidatas.put("hasRight", false);
            return apidatas;
        }

        apidatas.put("hasRight", true);

        ConditionFactory conditionFactory = new ConditionFactory(user);

        //条件组
        List<SearchConditionGroup> addGroups = new ArrayList<SearchConditionGroup>();

        List<SearchConditionItem> conditionItems = new ArrayList<SearchConditionItem>();

        //文本输入框
        SearchConditionItem logname = conditionFactory.createCondition(ConditionType.INPUT,502327, "logname");
        logname.setColSpan(2);//定义一行显示条件数，默认值为2,当值为1时标识该条件单独占一行
        logname.setFieldcol(16);	//条件输入框所占宽度，默认值18
        logname.setLabelcol(8);
        logname.setViewAttr(3);  //	 编辑权限  1：只读，2：可编辑， 3：必填   默认2
        logname.setLabel("日志名称"); //设置文本值  这个将覆盖多语言标签的值
        logname.setRules("required");
        conditionItems.add(logname);
        //文本输入框：路径类型
        SearchConditionItem ljlx = conditionFactory.createCondition(ConditionType.INPUT,502327, "ljlx");
        ljlx.setColSpan(2);//定义一行显示条件数，默认值为2,当值为1时标识该条件单独占一行
        ljlx.setFieldcol(16);	//条件输入框所占宽度，默认值18
        ljlx.setLabelcol(8);
        ljlx.setViewAttr(3);  //	 编辑权限  1：只读，2：可编辑， 3：必填   默认2
        ljlx.setLabel("路径类型"); //设置文本值  这个将覆盖多语言标签的值
        ljlx.setRules("required");
        conditionItems.add(ljlx);
        //日期格式
        SearchConditionItem queryDate = conditionFactory.createCondition(ConditionType.DATEPICKER,502327,"queryDate");
        queryDate.setValue(dateUtils.getYearMonthDay());
        queryDate.setColSpan(2);
        queryDate.setFieldcol(16);
        queryDate.setLabelcol(8);
        queryDate.setViewAttr(3);
        queryDate.setIsQuickSearch(true);
        queryDate.setLabel("日期");
        queryDate.setRules("required");
        conditionItems.add(queryDate);

        //时间区间
//        SearchConditionItem demo_timepicker = conditionFactory.createCondition(ConditionType.TIMERANGEPICKER,502327,new String[]{"seclevel1","seclevel2"});
//        demo_timepicker.setColSpan(2);
//        demo_timepicker.setFieldcol(12);
//        demo_timepicker.setLabelcol(6);
//        demo_timepicker.setViewAttr(3);
//        demo_timepicker.setLabel("时间区间");
//        demo_timepicker.setRules("required");
//        conditionItems.add(demo_timepicker);


        //文本输入框
//        SearchConditionItem ljlx = conditionFactory.createCondition(ConditionType.BROWSER,502327, "ljlx","17");
//        ljlx.setColSpan(2);//定义一行显示条件数，默认值为2,当值为1时标识该条件单独占一行
//        ljlx.setFieldcol(16);	//条件输入框所占宽度，默认值18
//        ljlx.setLabelcol(8);
//        ljlx.setViewAttr(2);  //	 编辑权限  1：只读，2：可编辑， 3：必填   默认2
//        ljlx.setLabel("路径类型"); //设置文本值  这个将覆盖多语言标签的值
//        conditionItems.add(ljlx);

        //下拉选择框类
//        SearchConditionItem demo_select = conditionFactory.createCondition(ConditionType.SELECT,502327,"state");
//        List<SearchConditionOption> selectOptions = new ArrayList <>();  //设置选项值
//        selectOptions.add(new SearchConditionOption("0","",true));
//        selectOptions.add(new SearchConditionOption("1","开始"));
//        selectOptions.add(new SearchConditionOption("2","流转"));
//        selectOptions.add(new SearchConditionOption("3","撤销"));
//        selectOptions.add(new SearchConditionOption("4","结束"));
//        demo_select.setOptions(selectOptions);
//        demo_select.setColSpan(2);
//        demo_select.setFieldcol(16);
//        demo_select.setLabelcol(8);
//        demo_select.setIsQuickSearch(false);
//        demo_select.setLabel("状态");
//        conditionItems.add(demo_select);
//
//
//        //下拉选择框类
//        SearchConditionItem type = conditionFactory.createCondition(ConditionType.SELECT,502327,"type");
//        List<SearchConditionOption> typeOptions = new ArrayList <>();  //设置选项值
//        typeOptions.add(new SearchConditionOption("0","",true));
//        typeOptions.add(new SearchConditionOption("1","类型一"));
//        typeOptions.add(new SearchConditionOption("2","类型二"));
//        typeOptions.add(new SearchConditionOption("3","类型三"));
//        type.setOptions(typeOptions);
//        type.setColSpan(2);
//        type.setFieldcol(16);
//        type.setLabelcol(8);
//        type.setIsQuickSearch(false);
//        type.setLabel("类型");
//        conditionItems.add(type);

        addGroups.add(new SearchConditionGroup("",true,conditionItems));

        apidatas.put("condition",addGroups);

        return apidatas;

    }
}
